﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
using Data;
namespace DAO
{
    public class Ban_DAO
    {
        public static List<Ban_DTO> SelectAll()
        {
            List<DTO.Ban_DTO> result = new List<DTO.Ban_DTO>();
            DataTable dt = Data.SQLAccess.ExecuteQuery("select *from BAN");
            DTO.Ban_DTO ban;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ban = new DTO.Ban_DTO();
                ban._Ma_Ban = int.Parse(dt.Rows[i]["MA_BAN"].ToString());
                ban._Ten_Ban = dt.Rows[i]["TEN_BAN"].ToString();
                ban._Ma_Tinh_Trang = int.Parse(dt.Rows[i]["MA_TINH_TRANG"].ToString());
                result.Add(ban);
            }
            return result;
        }
        public static string Insert(DTO.Ban_DTO ban)
        {
            try
            {
                string str_sql = "insert into BAN values("
                + ban._Ma_Ban + ",N'"
                + ban._Ten_Ban + "',"
                + ban._Ma_Tinh_Trang + ""
                + ")";
                DataTable dt = Data.SQLAccess.ExecuteQuery(str_sql);
                return "true";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
        public static string Delete(Ban_DTO ban)
        {
            try
            {
                return "true";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
    }
}
